package com.team.auth.controller;//package com.team.auth.controller;
//
//import com.team.auth.config.security.SsoProperites;
//import com.team.auth.config.security.enums.ResponseStatusEnum;
//import com.team.auth.controller.dto.LoginDto;
//import com.team.common.base.Common;
//import com.team.common.base.DataResult;
//import com.team.common.base.RequestData;
//import com.team.common.util.RedisUtil;
//import com.team.common.util.Utils;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.concurrent.TimeUnit;
//
//@RestController
//@Slf4j
//public class LoginController {
//    @Autowired
//    private AuthenticationManager authenticationManager;
//    @Autowired
//    private SsoProperites ssoProperites;
//
//
//
//    @RequestMapping("mylogin")
//    public DataResult<?> login(@RequestBody RequestData<LoginDto> loginDto){
//        LoginDto data = loginDto.getData();
//        String userName = data.getUserName();
//        String tokenId = Utils.getUUID();
//        UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userName,data.getPassword());
//        //认证
//        try {
//            Authentication authenticate = authenticationManager.authenticate(usernamePasswordAuthenticationToken);
//            SecurityContextHolder.getContext().setAuthentication(authenticate);
//            int sessionTime = ssoProperites.getSessionTime();
//            if (sessionTime <= 0){
//                sessionTime = 1800000;
//            }
//            RedisUtil.putObject(Common.SESSION_FIELD +tokenId,authenticate,sessionTime,TimeUnit.MILLISECONDS);
//        }catch (Exception e){
//            log.error("{}认识失败",userName);
//            return new DataResult(ResponseStatusEnum.LOGIN_FAILER.getCode(),ResponseStatusEnum.LOGIN_FAILER.getMsg());
//        }
//        return new DataResult(ResponseStatusEnum.LOGIN_SUCCESS.getCode(),ResponseStatusEnum.LOGIN_SUCCESS.getMsg(),tokenId);
//    }
//
//    @RequestMapping("test")
//    public String test(){
//        return "sss";
//    }
//
//}
